package com.ruoyi.production.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.production.domain.WorkReportMember;
import com.ruoyi.production.service.IWorkReportMemberService;
import com.ruoyi.production.service.IWorkReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

/**
 * 今日产出Controller
 *
 * @author ruoyi
 * @date 2022-09-05
 */
@RestController
@RequestMapping("/production/WorkReportMember")
public class WorkReportMemberController extends BaseController {
    @Autowired
    private IWorkReportMemberService workReportMemberService;

    @Autowired
    private IWorkReportService workReportService;

    /**
     * 查询今日产出列表
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportMember:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkReportMember workReportMember) {
        startPage();
        List<WorkReportMember> list = workReportMemberService.selectWorkReportMemberList(workReportMember);
        return getDataTable(list);
    }

    /**
     * 导出今日产出列表
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportMember:export')")
    @Log(title = "今日产出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkReportMember workReportMember) {
        List<WorkReportMember> list = workReportMemberService.selectWorkReportMemberList(workReportMember);
        ExcelUtil<WorkReportMember> util = new ExcelUtil<WorkReportMember>(WorkReportMember.class);
        util.exportExcel(response, list, "今日产出数据");
    }

    /**
     * 获取今日产出详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportMember:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(workReportMemberService.selectWorkReportMemberById(id));
    }

    /**
     * 新增今日产出
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportMember:add')")
    @Log(title = "今日产出", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkReportMember workReportMember) {
        return toAjax(workReportMemberService.insertWorkReportMember(workReportMember));
    }

    /**
     * 修改今日产出
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportMember:edit')")
    @Log(title = "今日产出", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkReportMember workReportMember) {
        return toAjax(workReportMemberService.updateWorkReportMember(workReportMember));
    }

    /**
     * 删除今日产出
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportMember:remove')")
    @Log(title = "今日产出", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(workReportMemberService.deleteWorkReportMemberByIds(ids));
    }


    /**
     * 入库
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportMember:warehousing')")
    @Log(title = "今日产出", businessType = BusinessType.DELETE)
    @GetMapping("/warehousing/{id}")
    public AjaxResult warehousing(@PathVariable Long id){
        return toAjax(workReportMemberService.warehousing(id));
    }

    /**
     * 打印二维码
     * @param response
     * @param id
     * @throws IOException
     * @throws URISyntaxException
     */
    @PreAuthorize("@ss.hasPermi('production:WorkReportMember:printQRcode')")
    @Log(title = "今日产出", businessType = BusinessType.DELETE)
    @GetMapping("/printQRcode/{id}")
    public void printQRcode(HttpServletResponse response,@PathVariable Long id) throws IOException, URISyntaxException {
       workReportMemberService.printQRcode(response,id);
    }

}
